package org.apache.dolphinscheduler.api.service.impl;

import org.apache.dolphinscheduler.api.page.PageQuery;
import org.apache.dolphinscheduler.api.page.TableDataInfo;
import org.apache.dolphinscheduler.api.service.RouterService;
import org.apache.dolphinscheduler.dao.entity.Router;
import org.apache.dolphinscheduler.dao.mapper.RouterMapper;

import org.apache.commons.lang3.StringUtils;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * <p>
 * 路由表 服务实现类
 * </p>
 *
 * @author denggh
 * @since 2023-02-08
 */
@Service
public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> implements RouterService {

    @Override
    public TableDataInfo<Router> selectPageRouterList(Router router, PageQuery pageQuery) {
        LambdaQueryWrapper<Router> lqw = new LambdaQueryWrapper<Router>();
        if (StringUtils.isNotBlank(router.getName())) {
            lqw.like(Router::getName, router.getName());
        }
        IPage<Router> page = baseMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public Router selectRouterById(Long routerId) {
        return baseMapper.selectById(routerId);
    }

    @Override
    public int insertRouter(Router router) {
        return baseMapper.insert(router);
    }

    @Override
    public int updateRouter(Router router) {
        return baseMapper.updateById(router);
    }

    @Override
    public int deleteRouterById(Long routerId) {
        return baseMapper.deleteById(routerId);
    }
}
